<?php

class sfBootstrapGenerator extends sfDoctrineGenerator {

    public function getLinkToAction($actionName, $params, $pk_link = false) {
        $action = isset($params['action']) ? $params['action'] : 'List' . sfInflector::camelize($actionName);

        $url_params = $pk_link ? '?' . $this->getPrimaryKeyUrlParams() : '\'';
        
        $id = rand(111111,999999);
        $icon = isset($params['icon']) ? '<i class="icon-'.$params['icon'].'"></i>&nbsp;' : '';
        $hint = isset($params['hint']) ? '\'<script>$(function(){ $("#'.$id.'").tooltip({ title: "'.$params['hint'].'" }); });</script>\'' : '\'\'';
        
        $params['params']['id'] = $id;
        
        $params['params']['class'] = 'btn';
        if(isset($params['size'])) {
            $params['params']['class'] .= ' btn-'.$params['size'];
        }
        if(isset($params['style'])) {
            $params['params']['class'] .= ' btn-'.$params['style'];
        }
        if(isset($params['icon-only']) && $params['icon-only'] == true) {
            return '[?php echo link_to(\'&nbsp;'.$icon.'\', \'' . $this->getModuleName() . '/' . $action . $url_params . ', ' . $this->asPhp($params['params']) . ').'.$hint.' ?]';
        } else {
            return '[?php echo link_to(\''.$icon.'\'.__(\'' . $params['label'] . '\', array(), \'' . $this->getI18nCatalogue() . '\'), \'' . $this->getModuleName() . '/' . $action . $url_params . ', ' . $this->asPhp($params['params']) . ').'.$hint.' ?]';
        }
    }

}